home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Broadcaster / BroadcastLink.h < prev    next >
Encoding:
Text File  |  1997-06-28  |  841 b   |  50 lines  |  [TEXT/CWIE]

  1. // BroadcastLink.h
  2.  
  3. #ifndef BroadcastLink_h
  4. #define BroadcastLink_h
  5.  
  6. #ifndef ListLink_h
  7. #include "ListLink.h"
  8. #endif
  9. #ifndef Broadcaster_h
  10. #include "Broadcaster.h"
  11. #endif
  12. #ifndef Enableable_h
  13. #include "Enableable.h"
  14. #endif
  15.  
  16. template < class Protocol >
  17. class BroadcastLink: public Enableable
  18.   {
  19.     typedef Broadcaster< Protocol > Source;
  20.     
  21.     private:
  22.         Source& broadcaster;
  23.         ListLink< Protocol > link;
  24.     
  25.     protected:
  26.         virtual void BeEnabled()
  27.           {
  28.             broadcaster.Add( link, afterEnd );
  29.           }
  30.  
  31.         virtual void BeDisabled()
  32.           {
  33.             broadcaster.Remove( link );
  34.           }
  35.     
  36.     public:
  37.         BroadcastLink( const Source& source,
  38.                             Protocol& target,
  39.                             bool startEnabled = true )
  40.           : Enableable( startEnabled ),
  41.              broadcaster( const_cast<Source&>( source ) ),
  42.              link( &target )
  43.           {
  44.             if ( startEnabled )
  45.                 BeEnabled();
  46.           }
  47.   };
  48.  
  49. #endif
  50.